﻿/*********************************************************************************
 *Author:         OnClick
 *Version:        1.0
 *UnityVersion:   2018.3.11f1
 *Date:           2019-04-07
 *Description:    IFramework
 *History:        2018.11--
*********************************************************************************/
using System;

namespace IFramework
{
	public static partial class StringConvert
	{
        public static string ToStr(this int self)
        {
            return self.ToString();
        }
        public static string ToStr(this short self)
        {
            return self.ToString();
        }
        public static string ToStr(this long self)
        {
            return self.ToString();
        }
        public static string ToStr(this UInt16 self)
        {
            return self.ToString();
        }
        public static string ToStr(this UInt32 self)
        {
            return self.ToString();
        }
        public static string ToStr(this UInt64 self)
        {
            return self.ToString();
        }
        public static string ToStr(this float self)
        {
            return self.ToString();
        }
        public static string ToStr(this double self)
        {
            return self.ToString();
        }
        public static string ToStr(this decimal self)
        {
            return self.ToString();
        }
        public static string ToStr(this string self)
        {
            return self;
        }
        public static string ToStr(this bool self)
        {
            return self.ToString();
        }
        public static string ToStr(this char self)
        {
            return self.ToString();
        }
        public static string ToStr(this byte self)
        {
            return self.ToString();
        }
        public static string ToStr(this object self,Type type)
        {
            if (self == null) return null;
            if (type == typeof(int)) return ((int)self).ToStr();
            if (type == typeof(float)) return ((float)self).ToStr();
            if (type == typeof(double)) return ((double)self).ToStr();
            if (type == typeof(decimal)) return ((decimal)self).ToStr();
            if (type == typeof(bool)) return ((bool)self).ToStr();
            if (type == typeof(char)) return ((char)self).ToStr();
            if (type == typeof(long)) return ((long)self).ToStr();
            if (type == typeof(short)) return ((short)self).ToStr();
            if (type == typeof(byte)) return ((byte)self).ToStr();
            if (type == typeof(UInt16)) return ((UInt16)self).ToStr();
            if (type == typeof(UInt32)) return ((UInt32)self).ToStr();
            if (type == typeof(UInt64)) return ((UInt64)self).ToStr();
            Log.E("Could Not Convert");
            return string.Empty;
        }


        public static object TryParse(this string self,Type type)
        {
            if (string.IsNullOrEmpty(self)) return null;
            if (type == typeof(string)) return self;
            if (type == typeof(int))
            {
                int res;
                if (self.TryParse(out res)) return res;
                return null;
            }
            if (type == typeof(float))
            {
                float res;
                if (self.TryParse(out res)) return res;
                return null;
            }
            if (type == typeof(double))
            {
                double res;
                if (self.TryParse(out res)) return res;
                return null;
            }
            if (type == typeof(decimal))
            {
                decimal res;
                if (self.TryParse(out res)) return res;
                return null;
            }
            if (type == typeof(bool))
            {
                bool res;
                if (self.TryParse(out res)) return res;
                return null;
            }
            if (type == typeof(char))
            {
                char res;
                if (self.TryParse(out res)) return res;
                return null;
            }
            if (type == typeof(long))
            {
                long res;
                if (self.TryParse(out res)) return res;
                return null;
            }
            if (type == typeof(short))
            {
                short res;
                if (self.TryParse(out res)) return res;
                return null;
            }
            if (type == typeof(byte))
            {
                byte res;
                if (self.TryParse(out res)) return res;
                return null;
            }
            if (type == typeof(UInt16))
            {
                UInt16 res;
                if (self.TryParse(out res)) return res;
                return null;
            }
            if (type == typeof(UInt32))
            {
                UInt32 res;
                if (self.TryParse(out res)) return res;
                return null;
            }
            if (type == typeof(UInt64))
            {
                UInt64 res;
                if (self.TryParse(out res)) return res;
                return null;
            }
            Log.E("Could Not Convert");
            return null;
        }
        public static bool TryParse(this string self, out UInt16 result)
        {
            return UInt16.TryParse(self, out result);
        }
        public static bool TryParse(this string self, out UInt32 result)
        {
            return UInt32.TryParse(self, out result);
        }
        public static bool TryParse(this string self, out UInt64 result)
        {
            return UInt64.TryParse(self, out result);
        }
        public static bool TryParse(this string self,out bool result)
        {
           return  bool.TryParse(self, out result);
        }
        public static bool TryParse(this string self, out float result)
        {
            return float.TryParse(self, out result);
        }
        public static bool TryParse(this string self, out int result)
        {
            return int.TryParse(self, out result);
        }
        public static bool TryParse(this string self, out long result)
        {
            return long.TryParse(self, out result);
        }
        public static bool TryParse(this string self, out short result)
        {
            return short.TryParse(self, out result);
        }
        public static bool TryParse(this string self, out byte result)
        {
            return byte.TryParse(self, out result);
        }
        public static bool TryParse(this string self, out double result)
        {
            return double.TryParse(self, out result);
        }
        public static bool TryParse(this string self, out decimal result)
        {
            return decimal.TryParse(self, out result);
        }
        public static bool TryParse(this string self, out char result)
        {
            return char .TryParse(self, out result);
        }

    }
}
